<!-- 系统Setup板块  -- 平台信息页面 -->
<template>
  <div>
    <r-search
      ref="search"
      labelWidth="250px"
      labelPosition="right"
      :searchData="searchData"
      :searchForm="searchForm"
      :searchHandle="searchHandle"
      :inline="false"
      :searchRules="searchRules"
    />
  </div>
</template>

<script>
export default {
  data() {
    var checkToFixedTwo = (rule, value, callback) => {
      const reg = /[^\d]/g;
      if (!reg.test(value)) {
        callback();
      } else {
        return callback(new Error("Please InputInteger Number"));
      }
    };
    return {
      searchData: {
        electric: ""
      },
      searchForm: [
        {
          type: "input",
          label: "Minimum Battery Level for Rental",
          placeholder: "Minimum Battery Level for Rental",
          prop: "electric",
          width: 250
        }
      ],
      searchHandle: [
        { type: "primary", label: "Save", handle: e => this.elFormSubmit() }
      ],
      searchRules: {
        electric: [
          { required: true, message: "Please Enter", trigger: "blur" },
          { validator: checkToFixedTwo, trigger: "blur" }
        ]
      },
      depositCheckEnable: false,
      isDepositCheckEnable: false,
      sinput: ""
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getData() {
      var res = await this.apis.operatorSettingGetss();
      let data = res.data || {};
      if (data) {
        this.searchData.electric = data.electric;
      }
    },
    // Save
    elFormSubmit() {
      this.$refs.search.$refs.ruleForm.validate(async valid => {
        if (valid) {
          let res = await this.apis.operatorSettingEdit(this.searchData);
          this.$message({
            message: res.message,
            type: res.code === 200 ? "success" : "error"
          });
          this.getData();
        }
      });
    }
  }
};
</script>

<style scoped lang="scss"></style>
